package leetcode_day._2021._202103;

/**
 * @author yzh
 * @data 2021/3/22 19:45
 * 位 1 的个数
 * n & (n - 1) != 0 就 +1
 */
public class _22_191 {

    public int hammingWeight(int n) {
        int ans = 0;
        while (n != 0) {
            n = n & (n - 1);
            ++ans;
        }
        return ans;
    }
}
